from funcall.FuncallInfo import FuncallInfo, aiapp, db


if __name__ == "__main__":
    # 创建数据库表
    with aiapp.app_context():
        FuncallInfo()
        print("删除表,有数据时无法删除")
        # 该db需要由FuncallInfo.py中提供
        # db.create_all()
        # 删除所有表
        db.drop_all()
        db.create_all()

        fiList=[]
        new_fi = FuncallInfo(req_args='{"name": "John", "age": 30}'
                             , log_text='{"name": "John", "age": 30}'
                             , remark='{"name": "John", "age": 30}'
                             ,description='asus'
                             )
        fiList.append(new_fi)
        new_fi = FuncallInfo(req_args='{"name": "John", "age": 30}'
                             , remark='{"name": "John", "age": 30}'
                             ,description='linux'
                             )
        print(new_fi.description)
        fiList.append(new_fi)
        # with app.app_context():
        db.session.add_all(fiList)
        # db.session.add(new_user)
        db.session.commit()  # 提交事务以保存到数据库
        fiList=FuncallInfo.query.all()
        print(new_fi.description)
        print({'users': [user.description for user in fiList]} )

#INSERT INTO funcall_info (req_args, remark) VALUES ('a', 'b')